<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="p" uri="/WEB-INF/tld/page.tld" %>
<script type="text/javascript">

$(function() {
	$("#order_date1").datepicker({dateFormat: 'yy-mm-dd'});
	$("#order_date2").datepicker({dateFormat: 'yy-mm-dd'});
	
	initDialog();
	
});

function query() {
	var start = $("#order_date1").val();
	start.replaceAll("-", "/");
	var end = $("#order_date2").val();
	end.replaceAll("-", "/");
	var date1 = new Date(start);
	var date2 = new Date(end);
	if(date1!=""&&date2!=""&&date1.getTime()>date2.getTime()) $.jqalert("起始日期不能大于截止日期！！");
	else {
		$.ajax({
			url:"${basePath}/trade/advance_list.htm",
			type:"post",
			data:$("#scat_order_form").serialize(),
			dataType:"html"
		}).done(function(data){
			var html = $("#advance_table").find("tr").first().html();
			var tr = $("<tr></tr>");
			tr.html(html);
			$("#advance_table").html(tr);
			$("#advance_table").append(data);
		});
	}
}

function reset() {
	$(":input", "#scat_order_form").not(":hidden").val("");
	$("#scat_order_form").find("select").val("");
}

function detail(oid, cid) {
	$(".main").load("${basePath}/trade/advance_detail.htm", {orderId:oid, customerId:cid});
}

function turnpage(page) {
	$("#scat_order_form").children().first().val(page);
	query();
}

function initDialog() {
	$("#full_balance_dialog").dialog({
		title:"付款信息",
		autoOpen: false,
		height: 400,
		width: 300,
		modal: true,
		buttons:[{
			text:"确定",
			click:function() {
				$.ajax({
					url:"${basePath}/trade/advance_full.htm?id="+$("#advance_id").val(),
					dataType:"json"
				}).done(function(data) {
					$("#full_balance_dialog").dialog("close");
					$.jqalert(data.msg, "提示", function() {
						if(data.isSuccess) query();
					})
				})
			}},{
			text:"取消",
			click:function() {
				$("#full_balance_dialog").dialog("close");
			}}]
	});
}

function full(id) {
	$("#full_balance_dialog").dialog("open");
	$("#advance_id").val(id);
}

</script>

 <div class="cont">
    <h2 class="title">查询条件：</h2>
    <div class="ui_sel clearfix">
    <form id="scat_order_form" method="post">
    <input type="hidden" name="pageNo">
    	<div class="label_box fl">
            <span class="sel_label fl">交易号：</span>
            <input type="text" name="order_no">
        </div>
        <div class="label_box fl">
            <span class="sel_label fl">交易日期：</span>
            <input id="order_date1" type="text" readonly="readonly" name="order_date1">
        </div>
        <div class="label_box fl">
            <span class="sel_label fl">至</span>
            <input id="order_date2" type="text" readonly="readonly" name="order_date2">
        </div>
        <div class="label_box fl">
            <span class="sel_label fl">客户名称：</span>
            <input type="text" class="text_input fl" name="customer_name">
        </div>
        <div class="label_box fl">
            <span class="sel_label fl">联系电话：</span>
            <input type="text" class="text_input fl" name="customer_tel">
        </div>
        <div class="label_box fl">
            <span class="sel_label fl">所属门店：</span>
            <select name="store_name">
                <option value="">--全部--</option>
                <c:forEach items="${login_user.stores }" var="store">
                	<option value="${store.store_name }"
                		<c:if test="${query.store_name eq store.store_name }">
	                		selected="selected"
	                	</c:if>
                	>${store.store_name }</option>
                </c:forEach>
            </select>
        </div>
        </form>
        <a href="javascript:;" class="green_btn btn fl" onclick="query();">确定</a>
        <a href="javascript:;" class="yellow_btn btn fl" onclick="reset();">重置</a>
    </div>
    <div class="ui">
        <table id="advance_table" class="table_list">
            <tr class="">
              <th class="">序号</th>
              <th>交易号</th>
              <th class="">交易日期</th>
              <th class="">应付金额（元）</th>
              <th class="">收款比例</th>
              <th class="">已收金额（元）</th>
              <th class="">客户名称</th>
              <th class="">联系电话</th>
              <th class="">付款结果</th>
              <th class="">是否发货</th>
              <th class="">所属门店</th>
              <th class="">明细</th>
              <th class="">操作</th>
            </tr>
            <jsp:include page="advance_list.jsp"/>
        </table>
    </div>
</div>

<div id="full_balance_dialog">
	<h4>确认款项已经全部结完。</h4>
	<input type="hidden" id="advance_id">
</div>

<p:page map="${page }"></p:page>